// Decompiled by DJ v2.3.3.38 Copyright 2000 Atanas Neshkov  Date: 03/11/2007 6:40:45
// Home Page : http//members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   PlanoDao.java

package ig.formato.dao;

import ig.formato.dao.abs.DAO;
import ig.formato.dto.PlanoDTO;
import ig.formato.util.IGFormatoException;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.sql.*;
import java.util.*;

public class PlanoDao extends DAO {

    public PlanoDao() {
    }

    public Object buscar(Integer id) throws IGFormatoException {
        try {
            /*connectionIgFormato = */            getConnection();
            prep = connectionIgFormato.prepareStatement("SELECT ID,IDINFORME FROM PLANO WHERE ID = ?");
            prep.setInt(1, id.intValue());
            resul = prep.executeQuery();
            if (resul.next()) {
                return getDatos(resul, new PlanoDTO());
            }
        } catch (ClassNotFoundException ex) {
            throw new IGFormatoException(ex);
        } catch (SQLException ex) {
            throw new IGFormatoException(ex);
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex);
        } finally {
            closeAll();
        }
        return null;
    }

    public Object buscarPorInforme(Integer id) throws IGFormatoException {
        try {
            /*connectionIgFormato = */            getConnection();
            prep = connectionIgFormato.prepareStatement("SELECT ID,IDINFORME FROM PLANO WHERE IDINFORME = ?");
            prep.setInt(1, id.intValue());
            resul = prep.executeQuery();
            if (resul.next()) {
                return getDatos(resul, new PlanoDTO());
            }
        } catch (ClassNotFoundException ex) {
            throw new IGFormatoException(ex);
        } catch (SQLException ex) {
            throw new IGFormatoException(ex);
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex);
        } finally {
            closeAll();
        }
        return null;
    }

    public Collection buscarTodos() throws IGFormatoException {
        Collection c = new ArrayList();
        try {
            /*connectionIgFormato = */            getConnection();
            prep = connectionIgFormato.prepareStatement("SELECT ID,IDINFORME FROM PLANO");
            resul = prep.executeQuery();
            for (; resul.next(); c.add(getDatos(resul, new PlanoDTO()))) {
                ;
            }

            return c;
        } catch (ClassNotFoundException ex) {
            throw new IGFormatoException(ex);
        } catch (SQLException ex) {
            throw new IGFormatoException(ex);
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex);
        } finally {
            closeAll();
        }
    }

    public Integer guardar(Object obj) throws IGFormatoException {
        PlanoDTO dto = (PlanoDTO) obj;
        try {
            /*connectionIgFormato = */            getConnection();
            if (dto.getId() == null) {
                prep = connectionIgFormato.prepareStatement("INSERT INTO PLANO(IDINFORME, ID) VALUES(?, ?)");
                dto.setId(getMaximoId("PLANO"));
            } else {
                prep = connectionIgFormato.prepareStatement("UPDATE PLANO SET IDINFORME=? WHERE ID=?");
            }
            setDatos(prep, dto, "IDINFORME, ID");
            prep.executeUpdate();
            return dto.getId();
        } catch (ClassNotFoundException ex) {
            throw new IGFormatoException(ex);
        } catch (SQLException ex) {
            throw new IGFormatoException(ex);
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex);
        } catch (Throwable ex) {
            throw new IGFormatoException(ex);            
        } finally {
            closeAll();
        }
    }

    public void eliminar(Integer id) throws IGFormatoException {
        try {
            /*connectionIgFormato = */            getConnection();
            prep = connectionIgFormato.prepareStatement("DELETE FROM PLANO WHERE ID = ?");
            prep.setInt(1, id.intValue());
            prep.executeUpdate();
        } catch (SQLException ex) {
            throw new IGFormatoException(ex);
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex);
        } finally {
            closeAll();
        }
    }

    public Object existe(Object obj) throws IGFormatoException {
        try {
            /*connectionIgFormato = */            getConnection();
            prep = connectionIgFormato.prepareStatement("SELECT ID FROM PLANO WHERE ID = ? AND IDFORMATO = ?");
            Integer data[] = (Integer[]) (Integer[]) obj;
            prep.setInt(1, data[0].intValue());
            prep.setInt(2, data[1].intValue());
            resul = prep.executeQuery();
            if (resul.next()) {
                return Integer.valueOf(resul.getInt("ID"));
            }
        } catch (SQLException ex) {
            throw new IGFormatoException(ex);
        } catch (IGFormatoException ex) {
            throw ex;            
        } catch (Exception ex) {
            throw new IGFormatoException(ex);
        } finally {
            closeAll();
        }
        return Boolean.valueOf(false);
    }
}
